package com.np.xxpermissions1;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatImageView;

/**
 * 自动回收的图像控件
 */
public class ImageViewRecycle extends AppCompatImageView {

    public ImageViewRecycle(Context context) {
        this(context, null);
    }

    public ImageViewRecycle(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ImageViewRecycle(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void setImageResource(int resId) {
        Utils.Display.recycle(this, true);
        super.setImageResource(resId);
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        Utils.Display.recycle(this, true);
        super.setImageDrawable(drawable);
    }

    @Override
    public void setImageBitmap(Bitmap bm) {
        Utils.Display.recycle(this, true);
        super.setImageBitmap(bm);
    }

    @Override
    public void setImageURI(Uri uri) {
        Utils.Display.recycle(this, true);
        super.setImageURI(uri);
    }

    @Override
    public void setBackgroundResource(int resId) {
        Utils.Display.recycle(this, false);
        super.setBackgroundResource(resId);
    }

    @Override
    public void setBackgroundDrawable(Drawable background) {
        Utils.Display.recycle(this, false);
        super.setBackgroundDrawable(background);
    }
}
